<template>
  <div class="xtx-goods-page">
    <div class="container" v-if="goodsInfo">
      <!-- 面包屑 -->
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem :to="'/category/' + goodsInfo.categories[1].id">{{
          goodsInfo.categories[1].name
        }}</XtxBreadItem>
        <XtxBreadItem :to="'/category/sub/' + goodsInfo.categories[0].id">{{
          goodsInfo.categories[0].name
        }}</XtxBreadItem>
        <XtxBreadItem>{{ goodsInfo.name }}</XtxBreadItem>
      </XtxBread>
      <!-- 商品信息 -->
      <div class="goods-info">
        <div class="media">
          <GoodsImage :images="goodsInfo.mainPictures"></GoodsImage>
          <GoodsSales :goods="goodsInfo"></GoodsSales>
        </div>
        <div class="spec">
          <!-- 商品名城 -->
          <GoodsName :goods="goodsInfo"></GoodsName>
          <!-- SKU属性选择 -->
          <GoodsSku :goods="goodsInfo"></GoodsSku>
          <!-- 数量选择盒子 -->
          <XtxNumbox v-model="goodsNum" label="数量"></XtxNumbox>

          <!-- 加入购物车按钮 -->
          <XtxButton type="primary" style="margin-top:20px">加入购物车</XtxButton>
        </div>
      </div>
      <!-- 商品推荐 -->
      <GoodsRelevant />
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs"></div>
          <!-- 注意事项 -->
          <div class="goods-warn"></div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside"></div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
import GoodsRelevant from './components/goods-relevant'
import GoodsImage from './components/goods-image.vue'
import GoodsName from './components/goods-name.vue'
import GoodsSales from './components/goods-sales.vue'
import GoodsSku from './components/goods-sku.vue'
import { goods } from '@/api/goods'
import { useRoute } from 'vue-router'
export default {
  name: 'XtxGoodsPage',
  components: { GoodsSales, GoodsRelevant, GoodsImage, GoodsName, GoodsSku },
  setup () {
    const goodsInfo = ref('')
    const route = useRoute()

    goods(route.params.id).then(res => {
      console.log(res.result)
      goodsInfo.value = res.result
    })

    // 购买数量
    const goodsNum = ref(1)

    return { goodsInfo, goodsNum }
  }
}
</script>

<style scoped lang="less">
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
</style>
